var axios = require("axios");
axios.defaults.withCredentials = true;
axios.defaults.baseURL = 'https://xgaffairs.uestc.edu.cn';
axios.defaults.headers.get['Cookie'] = 'JSESSIONID=433ae60a-7904-41d8-98e5-7444efd9a80f';
axios.defaults.headers.post['Cookie'] = 'JSESSIONID=433ae60a-7904-41d8-98e5-7444efd9a80f';

function MyRequest(url, type, param) {
    return new Promise(
        (resolve, reject) => {
            if (type == "post") {
                axios.post(url, param)
                    .then(function(response) {
                        resolve(response.data);
                    })
                    .catch(function(error) {
                        reject(error);
                    });
            } else if (type == "get") {
                axios.get(url)
                    .then(function(response) {
                        resolve(response.data);
                    })
                    .catch(function(error) {
                        reject(error);
                    });
            }
        }
    );
}

exports.MyRequest = MyRequest;